#pragma once
#include "OCMain/Thread/DefaultWorkQueue.h"
#include "OCMain/HttpClient.h"
#include "OCMain/Log.h"

namespace OCPP
{
	class MapCacherWorkQueue : public RequestHandler, public ResponseHandler
	{
	public:
		enum RequestType
		{
			RT_Type1,
			RT_Type2,
		};

		struct TaskRequest
		{
			String					url;
			String					path;
			String					fileName;
			String					layer;
			RequestType				type;
			friend std::ostream& operator<<(std::ostream& o, const TaskRequest& r)
			{
				(void)r; return o;
			}
		};

		MapCacherWorkQueue(bool start = true);
		~MapCacherWorkQueue();
		void startup();
		void processResponses();
		void addRequest(TaskRequest request, int priority = 0);
		void addDowload(String url,String path, String layer, String fileName)
		{
			TaskRequest request;
			request.url = url;
			request.path = path;
			request.fileName = fileName;
			request.layer = layer;
			addRequest(request);
		}
		static std::map<String, int> _badLayerMap;
	protected:
		CORE_AUTO_MUTEX;
		virtual Response* handleRequest(const Request* req, const WorkQueue* srcQ);
		virtual void handleResponse(const Response* res, const WorkQueue* srcQ);
		int					mWorkQueueChannel;
		DefaultWorkQueue	mDefaultWorkQueue;
	};
}



